Namespace Globals

    Module mGlobalVars

        Public Const PI As Double = 3.14159274F
        Private Const iniConfigFile As String = "\evoconfig.ini"
        Private Const iniOrigConfigFile As String = "\config.ini"

        ''''''''''''''''D E B U G   M O D E''''''''''''''''''''''''''''''''

        'enables debug output
        Public bDebugMode As Boolean = True '= False

        Public DEBUG_IDX As Integer
        Public DEBUG_X(9) As Integer
        Public DEBUG_Y(9) As Integer

        Public DEBUG_SHOWTEXT As Boolean

        Public Sub RefreshDebugXY()

        End Sub

        '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

        Public IsLoadingTiles As Boolean = True
        Public IsInGame As Boolean = False

        Public ShadowBlend As Single = 0.4F

        Public sIP As String
        Public iPort As Integer

        Public Enum GameState
            Auth = 0
            SelChar = 1
            Game = 2

            ServerSwitch = 4
        End Enum

        Public Enum DrawingMode
            Normal = 0
            Magic = 1
            Grayscale = 2
            SemiTransparent = 3
            Shadow = 4
            Tinted = 5
            Line = 6
            Text = 7
            Overlay = 8
            Tooltip = 9
        End Enum

        Public bEnding As Boolean
        Public gGameState As GameState
        Public sAppPath As String
        Public sDataPath As String
        Public sSoundPath As String
        Public sMapPath As String
        Public sRootPath As String
        Public sUsername As String

        Friend fGameForm As fGame
        Friend Crypto As EvoLib.Cryptography.Crypto = Nothing
        Friend iniConfig As EvoLib.Config.IniFile = Nothing

        Public fontSize As Integer

        Public Sub InitGlobals()

            Dim Sz As Single = -5.0F
            Dim sysfont As System.Drawing.Font

            Do
                fontSize = Constants.FontSize - Sz
                sysfont = New System.Drawing.Font(Constants.FontName, fontSize, FontStyle.Regular)
                If sysfont.GetHeight > CInt(Constants.FontSize * Constants.FontScaleRatio) Then
                    Sz += 0.5F
                Else
                    Exit Do
                End If
            Loop While sysfont.GetHeight > CInt(Constants.FontSize * Constants.FontScaleRatio)


            gGameState = GameState.Auth

            sAppPath = System.AppDomain.CurrentDomain.BaseDirectory()

            'sDataPath = "\\Nickpc\MirEvo\Client\Data\"
            'sSoundPath = "\\Nickpc\MirEvo\Client\Sound\"
            'sMapPath = "\\Nickpc\MirEvo\Client\Map\"

            sUsername = EvoLib.Protocol.DefaultUsername

            Dim tmpExePath As String = Reflection.Assembly.GetExecutingAssembly().Location
            If My.Application.CommandLineArgs.Count > 0 Then
                bDebugMode = My.Application.CommandLineArgs.Contains("-debug")
            End If

            'trim exe file
            tmpExePath = Left(tmpExePath, InStrRev(tmpExePath, "\") - 1)
            'trim Debug/Release diriniConfig.GetString("FOLDER", "DATA", 
            'If bDebugMode Then tmpExePath = Left(tmpExePath, InStrRev(tmpExePath, "\") - 1)
            'trim bin dir
            'tmpExePath = Left(tmpExePath, InStrRev(tmpExePath, "\"))


            If bDebugMode Then

                If FileIO.FileSystem.FileExists(tmpExePath & iniConfigFile) Then
                    FileIO.FileSystem.DeleteFile(tmpExePath & iniConfigFile)
                End If

                FileIO.FileSystem.CopyFile(tmpExePath & iniOrigConfigFile, tmpExePath & iniConfigFile)
                Application.DoEvents()

            End If

            '    iniConfig = New EvoLib.Config.IniFile(tmpExePath & iniConfigFile)
            '    Application.DoEvents()

            '    sRootPath = iniConfig.GetString("FOLDER", "ROOT", "D:\MirEvo-MAIN\MirEvoClient\")
            '    sDataPath = iniConfig.GetString("FOLDER", "DATA", "D:\MirEvo-MAIN\MirEvoClient\Data\")
            '    sSoundPath = iniConfig.GetString("FOLDER", "SOUND", "D:\MirEvo-MAIN\MirEvoClient\Sound\")
            '    sMapPath = iniConfig.GetString("FOLDER", "MAP", "D:\MirEvo-MAIN\MirEvoClient\Map\")
            '    DirectX.Windowed = True 'False
            '    DirectX.Adapter = 0 '1
            '    'Globals.bDebugMode = True

            '    sRootPath = iniConfig.GetString("FOLDER", "ROOT", "D:\MirEvo-MAIN\MirEvoClient\")

            'Else

            iniConfig = New EvoLib.Config.IniFile(tmpExePath & iniConfigFile)

            sRootPath = tmpExePath
            sDataPath = tmpExePath & "\Data\"
            sSoundPath = tmpExePath & "\Sound\"
            sMapPath = tmpExePath & "\Map\"
            DirectX.Windowed = True
            DirectX.Adapter = 0

            sRootPath = tmpExePath

            'End If

        End Sub

    End Module

End Namespace
